package cjlu.ea.h.service.impl;

import cjlu.ea.h.entity.Bjxx;
import cjlu.ea.h.mapper.F201BjxxMapper;
import cjlu.ea.h.service.F201BjxxService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-09-18
 */
@Service
public class F201BjxxServiceImpl extends ServiceImpl<F201BjxxMapper, Bjxx> implements F201BjxxService {
    @Override
    public List<Object> getbjxx(Bjxx bjxx, Long current, Long limit) {
        QueryWrapper<Bjxx> wrapper = new QueryWrapper<>();

        //条件查询
        if(bjxx.getXymc()!=null){//学院名称
            wrapper.likeRight("xymc",bjxx.getXymc());
        }
        if(bjxx.getZymc()!=null){//专业名称
            wrapper.likeRight("zymc",bjxx.getZymc());
        }
        if(bjxx.getBjmc()!=null){//班级名称
            wrapper.likeRight("bjmc",bjxx.getBjmc());
        }

        //分页显示
        Page<Bjxx> page = new Page<>(current,limit);
        baseMapper.selectPage(page,wrapper);

        //数据查询获取
        List<Bjxx> list = page.getRecords();
        Long total = page.getTotal();
        List<Object> res = new ArrayList<>();
        res.add(list);
        res.add(total);

        return res;
    }

    @Override
    public List<String> getZyList(List<Bjxx> list) {
        String xym = list.get(0).getXymc();
        List<String> res = baseMapper.getZyList(xym);


        return res;
    }

    @Override
    public List<String> getbjList(List<Bjxx> list) {
        List<String> res = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            res.add(list.get(i).getBjmc());
        }
        return res;
    }

    @Override
    public List<String> getXyList() {
        List<String> res = baseMapper.getXyList();
        return res;
    }
}
